Document - PyMuPDF documentation#Document.subset_fonts

subset_fonts(verbose=False, fallback=False)

PDF only: Investigate eligible fonts for their use by text in the document. If a font is supported and a size reduction is possible, that font is replaced by a version with a subset of its characters.

Use this method immediately before saving the document.

Parameters:
  • verbose (bool) – write various progress information to sysout. This currently only has an effect if fallback is True.
  • fallback (bool) – if True use the deprecated algorithm that makes use of package fontTools (which hence must be installed). If using the recommended value False (default), MuPDF’s native function is used – which is very much faster and can subset a broader range of font types. Package fontTools is not required then.

The greatest benefit can be achieved when creating new PDFs using large fonts like is typical for Asian scripts. When using the Story class or method Page.insert_htmlbox(), multiple fonts may automatically be included – without the programmer becoming aware of it.

In all these cases, the set of actually used unicodes mostly is very small compared to the number of glyphs available in the used fonts. Using this method can easily reduce the embedded font binaries by two orders of magnitude – from several megabytes down to a low two-digit kilobyte amount.

Creating font subsets leaves behind a large number of large, now unused PDF objects (“ghosts”). Therefore, make sure to compress and garbage-collect when saving the file. We recommend to use Document.ez_save().

Show/hide history

  • New in v1.18.7
  • Changed in v1.18.9
  • Changed in v1.24.2 use native function of MuPDF.

Printed 2026-10-17.

(echo:: @ ᯤ)